<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>php-ajax无刷新上传(带进度条)demo</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width , initial-scale=1.0 , user-scalable=0 , minimum-scale=1.0 , maximum-scale=1.0" />
<script type='text/javascript' src='__STATIC__/admin/uploadajax/js/jquery-2.0.3.min.js'></script>
<script type='text/javascript' src='__STATIC__/admin/uploadajax/js/jquery.form.js'></script>
<link href="__STATIC__/admin/uploadajax/css/style.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div style="width:500px;margin:10px auto; border:solid 1px #ddd; overflow:hidden; ">
  <form id='myupload' action="{:url('banner/uploadifyImg')}" method='post' enctype='multipart/form-data'>

      <input type="file" id="uploadphoto" name="images" value="请点击上传图片"  style="display:none;" />
      <input type="hidden" name="urlRoute" value="carousel/11"/>

      <div class="imglist"> </div>
      <!--<div class="progress">
        <div class="progress-bar" ><span class="percent"></span></div>
      </div>-->
      <a href="javascript:void(0);" onclick="uploadphoto.click()" class="uploadbtn">点击上传首页轮播图</a>
  </form>
</div>
<script type="text/javascript">
    $(document).ready(function(e) {
       /* var progress = $(".progress");
        var progress_bar = $(".progress-bar");
        var percent = $('.percent');*/
        $("#uploadphoto").change(function(){
            $("#myupload").ajaxSubmit({
                dataType:  'json', //数据格式为json
                beforeSend: function() { //开始上传
                    //progress.show();
                   /* var percentVal = '0%';
                    progress_bar.width(percentVal);
                    percent.html(percentVal);*/
                },
                uploadProgress: function(event, position, total, percentComplete) {
                  /*  var percentVal = percentComplete + '%'; //获得进度
                    progress_bar.width(percentVal); //上传进度条宽度变宽
                    percent.html(percentVal); //显示上传进度百分比*/
                },
                success: function(data) {
                    console.log(data);
                    if(data.state == 1){
                        var src = data.path;
                        var attstr= '<img src="'+src+'">';

                        $(".imglist").append(attstr);
                        $("#bannerm_img").val(data.path);
                        //$(".res").html("上传图片"+data.name+"成功，图片大小："+data.size+"K,文件地址："+data.url);
                    }else{
                        $(".res").html(data.errmsg);
                    }
                    //progress.hide();
                },
                error:function(xhr){ //上传失败
                    alert("上传失败");
                    progress.hide();
                }
            });
        });

    });
</script>
</body>
</html>